package leetcode.code1642;

import java.util.PriorityQueue;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int furthestBuilding(int[] heights, int bricks, int ladders) {
		int sum = 0, ans = 0;
		PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
		for (int i = 1; i < heights.length; i++) {
			int h1 = heights[i - 1], h2 = heights[i];
			if (h2 > h1) {
				queue.add(h2 - h1);
				if (queue.size() > ladders) {
					sum += queue.poll();
					if (sum > bricks) {
						return ans;
					}
				}
			}
			ans = i;
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
